package com.oocl.command;

import java.io.IOException;
import java.io.OutputStream;
import java.util.List;

import com.oocl.dao.DeptmentDao;
import com.oocl.dao.PersonDao;
import com.oocl.dao.impl.DeptmentDaoImpl;
import com.oocl.dao.impl.PersonDaoImpl;
import com.oocl.server.po.Deptment;
import com.oocl.server.po.Person;

public class Query {
	private static String line;
	private static OutputStream out;

	public Query(String line, OutputStream out) {
		super();
		this.line = line;
		this.out = out;
	}

	public void QueryPersonALL() throws IOException {
		PersonDao personDao = new PersonDaoImpl();
		//KeyValue kv = new KeyValue(line);
		List<Person> persons = personDao.belongDetp();
		if (!persons.isEmpty()) {
			for (Person person2 : persons) {
				out.write((person2.toStringWithDept() + "\n").getBytes());
			}
			//out.write("over".getBytes());
		}
		
	}

	public void QueryDeptALL() throws IOException {
		DeptmentDao deptDao = new DeptmentDaoImpl();
		List<Deptment> dept = deptDao.listDept();
		if (!dept.isEmpty()) {
			for (Deptment deptment : dept) {
				out.write((deptment.toString() + "\n").getBytes());
			}
			//out.write("over".getBytes());
		}
	}

	public void QueryPerDept() throws IOException {
		PersonDao personDao = new PersonDaoImpl();
		KeyValue kv = new KeyValue(line);
		List<Person> persons = personDao.showDeptPerson(kv.getId());
		if (!persons.isEmpty()) {
			for (Person person : persons) {
				out.write((person.toString() + "\n").getBytes());
			}
			//out.write("over".getBytes());
		}
	}
}
